//引入
import {reqTradeInfo,reqOrderInfo}from '@/api';
const state = {
    address:{},//用户地址信息
    orderInfo:{},//商品清单数据
};
///修改 state 数据
const mutations ={
    //修改信息 address
    GETUSERADDRESS(state, address){
        state.address = address;
    },
    //修改 orderInfo 信息
    GETORDERINFO(state, orderInfo){
        state.orderInfo = orderInfo;
    }
};
const actions ={
    //这里要使用老师的账号才有数据  13700000000   111111
    //获取用户地址信息
    async getUserAddress({commit}){
        let result = await reqTradeInfo();
        console.log(result);
        if(result.code == 200){
            //提交commit
            commit('GETUSERADDRESS',result.data);
            return "ok";
        }else{
            return Promise.reject(new Error('faile'));
        }
    },
    //获取商品清单数据
   async getOrderInfo({commit}){
    //async和await是等待数据返回来
        //这个 reqOrderInfo() 返回的是一个Promise对象
      let result = await  reqOrderInfo();
      if(result.code == 200){
        //如果成功了就 commit 出去，让mutations修改 state的数据
        commit('GETORDERINFO',result.data);
      }
    }
};
const getters ={};
export default {
    state,
    mutations,
    actions,
    getters
}